home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / e33el2.zip / emacs / 19.33 / lisp / viper-keym.el < prev    next >
Lisp/Scheme  |  1996-05-23  |  24KB  |  554 lines

  1. ;;; viper-keym.el --- Viper keymaps
  2.  
  3. ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
  4.  
  5. ;; This file is part of GNU Emacs.
  6.  
  7. ;; GNU Emacs is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation; either version 2, or (at your option)
  10. ;; any later version.
  11.  
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ;; GNU General Public License for more details.
  16.  
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  19. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. ;; Boston, MA 02111-1307, USA.
  21.  
  22. ;; Code
  23.  
  24. (require 'viper-util)
  25.  
  26. ;;; Variables
  27.  
  28. ;;; Keymaps
  29.  
  30. ;; Keymaps for vital things like \e and C-z.
  31. ;; Not for users
  32. (defvar vip-vi-intercept-map (make-sparse-keymap))
  33. (defvar vip-insert-intercept-map (make-sparse-keymap))
  34. (defvar vip-emacs-intercept-map (make-sparse-keymap))
  35.  
  36. ;; keymap used to zap all keymaps other than function-key-map,
  37. ;; device-function-key-map, etc.
  38. (defvar vip-overriding-map (make-sparse-keymap))
  39.   
  40. (vip-deflocalvar vip-vi-local-user-map (make-sparse-keymap)
  41.   "Keymap for user-defined local bindings.
  42. Useful for changing bindings such as ZZ in certain major modes.
  43. For instance, in letter-mode, one may want to bind ZZ to
  44. mh-send-letter. In a newsreader such as gnus, tin, or rn, ZZ could be bound
  45. to save-buffers-kill-emacs then post article, etc.")
  46. (put 'vip-vi-local-user-map 'permanent-local t)    
  47.  
  48. (defvar vip-vi-global-user-map (make-sparse-keymap)
  49.   "Keymap for user-defined global bindings.
  50. These bindings are seen in all Viper buffers.")
  51.  
  52. (defvar vip-vi-basic-map (make-keymap)
  53.   "This is the main keymap in effect in Viper's Vi state.
  54. This map is global, shared by all buffers.")
  55.  
  56. (defvar  vip-vi-kbd-map (make-sparse-keymap)
  57.   "This keymap keeps keyboard macros defined via the :map command.")
  58.  
  59. (defvar vip-vi-diehard-map (make-sparse-keymap)
  60.   "This keymap is in use when the user asks Viper to simulate Vi very closely.
  61. This happens when vip-expert-level is 1 or 2. See vip-set-expert-level.")
  62.   
  63.  
  64. (vip-deflocalvar vip-insert-local-user-map (make-sparse-keymap)
  65.   "Auxiliary map for per-buffer user-defined keybindings in Insert state.")
  66. (put 'vip-insert-local-user-map 'permanent-local t)    
  67.  
  68. (defvar vip-insert-global-user-map (make-sparse-keymap)
  69.   "Auxiliary map for global user-defined bindings in Insert state.")
  70.  
  71. (defvar vip-insert-basic-map (make-sparse-keymap)
  72.   "The basic insert-mode keymap.")
  73.  
  74. (defvar vip-insert-diehard-map (make-keymap)
  75.   "Map used when user wants vi-style keys in insert mode.
  76. Most of the Emacs keys are suppressed. This map overshadows
  77. vip-insert-basic-map. Not recommended, except for novice users.")
  78.  
  79. (defvar  vip-insert-kbd-map  (make-sparse-keymap)
  80.   "This keymap keeps VI-style kbd macros for insert mode.")
  81.  
  82. (defvar vip-replace-map (make-sparse-keymap)
  83.   "Map used in Viper's replace state.")
  84.   
  85. (defvar vip-emacs-global-user-map (make-sparse-keymap)
  86.   "Auxiliary map for global user-defined bindings in Emacs state.")
  87.  
  88. (defvar  vip-emacs-kbd-map  (make-sparse-keymap)
  89.   "This keymap keeps Vi-style kbd macros for emacs mode.")
  90.   
  91. (vip-deflocalvar vip-emacs-local-user-map  (make-sparse-keymap)
  92.   "Auxiliary map for local user-defined bindings in Emacs state.")
  93. (put 'vip-emacs-local-user-map 'permanent-local t)  
  94.  
  95. ;; This keymap should stay empty
  96. (defvar vip-empty-keymap (make-sparse-keymap))
  97.  
  98. ;; This was the main Vi mode in old versions of VIP which may have been
  99. ;; extensively used by VIP users. We declare it as a global var
  100. ;; and, after .vip is loaded, we add this keymap to vip-vi-basic-map.
  101. (defvar vip-mode-map (make-sparse-keymap))
  102.  
  103.  
  104. ;;; Variables used by minor modes
  105.  
  106. ;; Association list of the form 
  107. ;; ((major-mode . keymap) (major-mode . keymap) ...)
  108. ;; Viper uses these keymaps to make user-requested adjustments
  109. ;; to its Vi state in various major modes.")
  110. (defvar vip-vi-state-modifier-alist nil)
  111.  
  112. ;; Association list of the form 
  113. ;; ((major-mode . keymap) (major-mode . keymap) ...)
  114. ;; Viper uses these keymaps to make user-requested adjustments
  115. ;; to its Insert state in various major modes.")
  116. (defvar vip-insert-state-modifier-alist nil)
  117.  
  118. ;; Association list of the form 
  119. ;; ((major-mode . keymap) (major-mode . keymap) ...)
  120. ;; Viper uses these keymaps to make user-requested adjustments
  121. ;; to its Emacs state in various major modes.
  122. (defvar vip-emacs-state-modifier-alist nil)
  123.  
  124. ;; Tells vip-add-local-keys to create a new vip-vi-local-user-map for new
  125. ;; buffers. Not a user option.
  126. (vip-deflocalvar vip-need-new-vi-local-map t "")
  127. (put 'vip-need-new-vi-local-map  'permanent-local t)
  128.  
  129. ;; Tells vip-add-local-keys to create a new vip-insert-local-user-map for new
  130. ;; buffers. Not a user option.
  131. (vip-deflocalvar vip-need-new-insert-local-map t "")
  132. (put 'vip-need-new-insert-local-map  'permanent-local t)
  133.  
  134. ;; Tells vip-add-local-keys to create a new vip-emacs-local-user-map for new
  135. ;; buffers. Not a user option.
  136. (vip-deflocalvar vip-need-new-emacs-local-map t "")
  137. (put 'vip-need-new-emacs-local-map  'permanent-local t)
  138.  
  139.  
  140.  
  141. ;; Insert mode keymap
  142.  
  143. ;; for novice users, pretend you are the real vi.
  144. (define-key vip-insert-diehard-map "\t"   'vip-insert-tab)
  145. (define-key vip-insert-diehard-map "\C-a" 'self-insert-command)
  146. (define-key vip-insert-diehard-map "\C-b" 'self-insert-command)
  147. (define-key vip-insert-diehard-map "\C-c" 'vip-change-state-to-vi)
  148. (define-key vip-insert-diehard-map "\C-e" 'self-insert-command)
  149. (define-key vip-insert-diehard-map "\C-f" 'self-insert-command)
  150. (define-key vip-insert-diehard-map "\C-g" 'self-insert-command)
  151. (define-key vip-insert-diehard-map "\C-i" 'self-insert-command)
  152. (define-key vip-insert-diehard-map "\C-k" 'self-insert-command)
  153. (define-key vip-insert-diehard-map "\C-l" 'self-insert-command)
  154. (define-key vip-insert-diehard-map "\C-n" 'self-insert-command)
  155. (define-key vip-insert-diehard-map "\C-o" 'self-insert-command)
  156. (define-key vip-insert-diehard-map "\C-p" 'self-insert-command)
  157. (define-key vip-insert-diehard-map "\C-q" 'self-insert-command)
  158. (define-key vip-insert-diehard-map "\C-r" 'self-insert-command)
  159. (define-key vip-insert-diehard-map "\C-s" 'self-insert-command)
  160. (define-key vip-insert-diehard-map "\C-u" 'vip-erase-line)
  161. (define-key vip-insert-diehard-map "\C-x" 'self-insert-command)
  162. (define-key vip-insert-diehard-map "\C-y" 'self-insert-command)
  163. (define-key vip-insert-diehard-map "\C-z" 'self-insert-command)
  164. (define-key vip-insert-diehard-map "\C-]" 'self-insert-command)
  165. (define-key vip-insert-diehard-map "\C-_" 'self-insert-command)
  166.  
  167. (let ((i ?\ ))
  168.   (while (<= i ?~)
  169.     (define-key vip-insert-diehard-map (make-string 1 i) 'self-insert-command)
  170.     (setq i (1+ i))))
  171.  
  172. ;; Insert mode map when user wants emacs style
  173. (define-key vip-insert-basic-map "\C-d" 'vip-backward-indent)
  174. (define-key vip-insert-basic-map "\C-w" 'vip-delete-backward-word)
  175. (define-key vip-insert-basic-map "\C-t" 'vip-forward-indent)
  176. (define-key vip-insert-basic-map 
  177.   (if vip-xemacs-p [(shift tab)] [S-tab]) 'vip-insert-tab)
  178. (define-key vip-insert-basic-map "\C-v" 'quoted-insert)
  179. (define-key vip-insert-basic-map "\C-?" 'vip-del-backward-char-in-insert)
  180. (define-key vip-insert-basic-map "\C-c\M-p"
  181.   'vip-insert-prev-from-insertion-ring)
  182. (define-key vip-insert-basic-map "\C-c\M-n"
  183.   'vip-insert-next-from-insertion-ring)
  184.  
  185.  
  186. ;; Replace keymap
  187. (define-key vip-replace-map "\C-t" 'vip-forward-indent)
  188. (define-key vip-replace-map "\C-j" 'vip-replace-state-exit-cmd)
  189. (define-key vip-replace-map "\C-m" 'vip-replace-state-exit-cmd)
  190. (define-key vip-replace-map "\C-?" 'vip-del-backward-char-in-replace)
  191.  
  192.  
  193.  
  194. ;; Vi keymaps
  195.  
  196. (define-key vip-vi-basic-map "\C-^" 
  197.   (function (lambda () (interactive) (vip-ex "e#"))))
  198. (define-key vip-vi-basic-map "\C-b" 'vip-scroll-back)
  199. (define-key vip-vi-basic-map "\C-